home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / smaltalk / stv.lha / STV / ISA / carolina / errorhnd.st < prev    next >
Text File  |  1993-07-23  |  2KB  |  60 lines

  1. "evaluate the following code to install 
  2. ErrorHandler. source: SCOOP Spring '89"
  3. "[1//0] ifError:
  4.     [:aString | 
  5.     aString = 'divisor is zero'
  6.         ifTrue: [0]
  7.         ifFalse: [
  8.             self error: aString]]"
  9. "*******************************************"
  10.  
  11. Process class compile:
  12.     'allInstances 
  13.     ^Array new'.
  14. OrderedCollection subclass: #Process
  15.     instanceVariableNames:
  16.     'topFrame frameBias priority
  17.     sendFrame isUserIF debugger
  18.     name interruptFrame
  19.     errorHandler'
  20.     classVariableNames: ''
  21.     poolDictionaries: ''.
  22. Process class removeSelector:
  23.     #allInstances.
  24. Processor initialize. 
  25. "*******************************************"
  26. "Install the following methods"
  27. "Object methods ****************************"
  28.     error: aString
  29. "Create a walkback window describing an
  30. error condition with the error message
  31. aString in the window label"
  32.     CurrentProcess isErrorHandled
  33.         ifTrue: [CurrentProcess errorHandler
  34.                 value: aString].
  35.     Process queueWalkback: aString
  36.         makeUserIF: CurrentProcess
  37.         isUserIF resumable: false
  38. "Process methods ***************************"
  39.     errorHandler
  40.     ^errorHandler
  41.     errorHandler: aBlock
  42.     errorHandler := aBlock
  43.     isErrorHandled
  44.     ^errorHandler notNil
  45. "Context methods ***************************"
  46.     ifError: aBlock
  47.     |errorBlock lastHandler |
  48.     lastHandler := CurrentProcess
  49.         errorHandler.
  50.     errorBlock := [:aString |
  51.         CurrentProcess errorHandler:
  52.             lastHandler.
  53.         ^aBlock value: aString].
  54.     currentProcess errorhandler:
  55.         errorBlock.
  56.     self value.
  57.     CurrentProcess errorHandler:
  58.         lastHandler
  59.  
  60.